/* 
 * Bitmain Tech, Home of Professional Bitmain Tech
 * Copyright 2014 Bitmain Tech Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 */
package com.bitmain.mmst.core.struct;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.bitmain.mmst.common.consts.Consts;
import com.bitmain.ulnar.aider.DateAider;

/**
 * 结构体：接口执行结果
 * 
 * @author Kweny - enkun.jiang@bitmain.com
 * @since 2015年12月11日
 */
public class APIResult implements Consts {
	private int code = INFO.INFO;
	private Boolean success = Boolean.TRUE;
	private String message;
	private Object data;
	
	public void setInfo(HttpServletRequest request, int code, Object... args) {
		setCode(request, Boolean.TRUE, code, args);
	}
	
	public void setWarn(HttpServletRequest request, int code, Object... args) {
		setCode(request, null, code, args);
	}
	
	public void setError(HttpServletRequest request, int code, Object... args) {
		if (code == ERROR.ERROR) {
			args = new Object[] {DateAider.formatDate(new Date())};
		}
		setCode(request, Boolean.FALSE, code, args);
	}
	
	public void setCode(HttpServletRequest request, Boolean success, int code, Object... args) {
		this.code = code;
		this.success = success;
		this.message = Message.get(request, code, args);
	}

	/**
	 * @return the code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setCode(int code) {
		this.code = code;
	}

	/**
	 * @return the success
	 */
	public Boolean getSuccess() {
		return success;
	}

	/**
	 * @param success
	 *            the success to set
	 */
	public void setSuccess(Boolean success) {
		this.success = success;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message
	 *            the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the data
	 */
	public Object getData() {
		return data;
	}

	/**
	 * @param data
	 *            the data to set
	 */
	public void setData(Object data) {
		this.data = data;
	}
}
